/**
 *
 */
package com.angel.resourceBundle.daos.propertyValue.impl;

import java.io.Serializable;
import java.util.Collection;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import com.angel.dao.generic.impl.GenericHibernateDAO;
import com.angel.resourceBundle.daos.propertyValue.PropertyValueDAO;
import com.angel.resourceBundle.propertyValue.PropertyValue;

/**
 * @author William
 *
 */
public abstract class PropertyValueHibernateDAO<T extends PropertyValue, Code extends Serializable> extends GenericHibernateDAO<T, Code> implements PropertyValueDAO<T, Code>{

	@SuppressWarnings("unchecked")
	public void deleteUniqueByExtendedKey(String extendedKey) {
		super.delete((T) this.findUniqueByExtendedKey(extendedKey));
	}

	public PropertyValue findUniqueByExtendedKey(String extendedKey) {
		return super.findUnique("extendedKey", extendedKey);
	}
	
	public PropertyValue findUniqueOrNullByExtendedKey(String extendedKey) {
		return super.findUniqueOrNull("extendedKey", extendedKey);
	}

	@SuppressWarnings("unchecked")
	public Collection<PropertyValue> findAllByResourceBundleContextKey(String contextKey) {
		return (Collection<PropertyValue>) super.findAllByCriteria(Restrictions.like("extendedKey", contextKey, MatchMode.START));
	}

	public Long countAllWithExtendedKey(String extendedKey){
		return super.count("extendedKey", extendedKey);
	}

	@SuppressWarnings("unchecked")
	public Collection<PropertyValue> findAllByExtendedKey(String[] extendedKeys){
		return (Collection<PropertyValue>) super.findAllByCriteria(Restrictions.in("extendedKey", extendedKeys));
	}
}
